import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [vue()],
	resolve: {
		alias: {
			'@': resolve(__dirname, './src'),
		},
	},
	server: {
		port: 3000,
		host: '0.0.0.0',
		open: true,
		proxy: {
			'/api': {
				target: 'http://localhost:8080',
				changeOrigin: true,
			},
		},
	},
	build: {
		minify: 'terser', // 使用terser进行更好的压缩
		rollupOptions: {
			output: {
				manualChunks: {
					// 将大依赖包单独拆分
					'element-plus': ['element-plus'],
					'vue-vendor': ['vue', 'vue-router', 'pinia'],
					editor: ['@wangeditor/editor', '@wangeditor/editor-for-vue'],
					echarts: ['echarts'],
				},
				// 控制chunk大小
				chunkFileNames: 'assets/js/[name]-[hash].js',
				entryFileNames: 'assets/js/[name]-[hash].js',
				assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
			},
		},
		// 设置chunk大小警告阈值
		chunkSizeWarningLimit: 1500,
	},
})
